<include file="Public/header"/>
<include file="Public/menu"/>

<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            活动专题
            <small>管理</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="{:U('index/index')}"><i class="fa fa-dashboard"></i> 活动专题</a></li>
            <li><a href="{:U('Special/cart')}"><i class="fa fa-dashboard"></i> 店铺专题</a></li>
            <li class="active">专题商品包</li>
        </ol>
    </section>

    <!-- 内容 -->
    <section class="content">

        <div class="tab-content">
            <div class="tab-pane active" id="tab_0">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title"></h3>
                        <div class="form-inline pull-right">
                            <form action="{:U('Special/cart')}" method="get" pjax-container="">
                                <fieldset>
                                    <div class="input-group input-group-sm">
                                        <span class="input-group-addon"><strong>分类名称</strong></span>
                                        <input type="hidden" name="search_field" value="type_name">
                                        <div class="input-group input-group-sm">
                                            <input type="text" class="form-control" placeholder="搜索" name="search" value="{$search}">
                                        </div>
                                    </div>

                                    <div class="input-group input-group-sm">
                                        <div class="input-group-btn">
                                            <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i>
                                            </button>
                                        </div>
                                    </div>
                                </fieldset>
                            </form>
                        </div>

                        <div class="btn-group pull-right" style="margin-right: 10px">
                            <a href="{:U('Special/addCart')}" class="btn btn-sm btn-success"><i class="fa fa-save"></i>&nbsp;&nbsp;新增</a>
                        </div>

                    </div>
                    <!-- /.box-header -->
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <tbody>
                            <tr>
                                <th><!--<input type="checkbox" class="grid-select-all">--></th>
                                <th>ID<a class="fa fa-fw fa-sort" href="{:U('Special/cart',array('p'=>$p,'order_field'=>'type_id','order'=>$order), '')}"></a></th>
                                <th>分类名称</th>
                                <th>专题商品个数</th>
                                <th>操作</th>
                            </tr>
                            <volist name="list" id="vo">
                                <tr>
                                    <td><!--<input type="checkbox" class="grid-item" data-id="{$vo.id}">--></td>
                                    <td>{$vo.type_id}</td>
                                    <td>{$vo.type_name}</td>
                                    <td>{$vo.num}</td>
                                    <td>
                                        <a href="{:U('Special/editCart', array('type_id'=>$vo['type_id']), '')}" class="btn btn-sm btn-primary grid-refreshe">编辑</a>
                                        <a href="javascript:void(0);" data-id="{$vo.type_id}" class="btn btn-sm btn-danger _delete">删除</a>
                                    </td>
                                </tr>
                            </volist>
                            </tbody>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        <!--<input type="checkbox" class="grid-select-all">-->&nbsp;&nbsp;&nbsp;
                        <!--<a class="btn btn-sm btn-danger batch-delete">批量删除</a>-->
                        <a class="btn btn-sm btn-primary grid-refresh"><i class="fa fa-refresh"></i></a>
                        {$page}
                    </div>
                    <!-- /.box-body -->
                </div>
            </div>

        </div>
    </section>
</div>
<!-- 底部 -->
<include file="Public/common_footer"/>
<script data-exec-on-popstate>

    $(function () {

        $('.grid-select-all').change(function () {
            if (this.checked) {
                $('.grid-item').prop("checked", true);
            } else {
                $('.grid-item').prop("checked", false);
            }
        });

        $('._delete').click(function () {
            if(!confirm("确认删除")){
                return false;
            }
            var id = $(this).attr('data-id');
            if (id) {
                $.ajax({
                    type: "POST",
                    url: "{:U('Special/delCart')}",
                    data: {id:id},
                    success: function(msg){
                        alert(msg.message);
                        window.location.reload();
                    },
                    error: function (msg) {
                        alert(msg.message);
                    }
                });
            }
        });

        $('.batch-delete').on('click',function(e){
            if(!confirm("确认批量删除")){
                return false;
            }
            var data = [];
            $(".grid-item[type='checkbox']:checked").each(function (i) {
                var id = $(this).attr('data-id');
                data.push(id);
                $(this).parent().parent().remove();
            });
            if (data) {
                $.ajax({
                    type: "POST",
                    url: "{:U('Special/del')}",
                    data: {id:data},
                    success: function(msg){
                        console.log(msg.message);
                    },
                    error: function (msg) {
                        alert(msg.message);
                    }
                });
            }
        })

    });
</script>